package indi.zhifa.study2025.class001.eltest.controller;

import indi.zhifa.core.common.web.entity.ann.ZhiFaRestController;
import indi.zhifa.study2025.class001.eltest.gen.item.po.GenItemEntity;
import indi.zhifa.study2025.class001.eltest.logic.IItemService;
import indi.zhifa.study2025.class001.eltest.logic.entity.ItemRequest;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Validated
@RequiredArgsConstructor
@RequestMapping(value = "/api/curd/item")
@ZhiFaRestController
@Tag(name = "商品增删改查")
public class ItemController {

    final IItemService mItemService;

    @PostMapping
    public GenItemEntity addItem(@RequestBody ItemRequest pItemEntity){
        return mItemService.addItem(pItemEntity);
    }

    @PutMapping("/{id}")
    public GenItemEntity updateItem(@PathVariable(name = "id") Long pId,
                                    @RequestBody ItemRequest pItemEntity){
        return mItemService.updateItem(pId, pItemEntity);
    }

    @GetMapping("/{id}")
    public GenItemEntity info(@PathVariable(name = "id") Long pId){
        return mItemService.info(pId);
    }

    @DeleteMapping("/{id}")
    public GenItemEntity deleteItem(@PathVariable(name = "id") Long pId){
        return mItemService.deleteItem(pId);
    }
}
